import Vue from 'vue'
import App from './App.vue'
import router from '../router'
import store from './store'
import http from 'axios'
import "../api/mock.js"
// 应用elementUI插件
// 应用了哪些标签,就往下面的对象里写
import { Button, Row, Col, Container, Aside, Main, Header, Menu, Submenu, MenuItem, MenuItemGroup, Dropdown, DropdownMenu, DropdownItem, Card, Table, TableColumn, Breadcrumb, BreadcrumbItem, Tag, Input, Select, Switch, DatePicker, Option, Dialog, Form, FormItem, Pagination, Message, MessageBox } from "element-ui"
Vue.component(Button.name, Button);
Vue.component(Row.name, Row);
Vue.component(Col.name, Col);
Vue.component(Container.name, Container);
Vue.component(Aside.name, Aside);
Vue.component(Main.name, Main);
Vue.component(Header.name, Header);
Vue.component(Menu.name, Menu);
Vue.component(Submenu.name, Submenu);
Vue.component(MenuItem.name, MenuItem);
Vue.component(MenuItemGroup.name, MenuItemGroup);
Vue.component(Dropdown.name, Dropdown);
Vue.component(DropdownMenu.name, DropdownMenu);
Vue.component(DropdownItem.name, DropdownItem);
Vue.component(Card.name, Card);
Vue.component(Table.name, Table);
Vue.component(TableColumn.name, TableColumn);
Vue.component(Breadcrumb.name, Breadcrumb);
Vue.component(BreadcrumbItem.name, BreadcrumbItem);
Vue.component(Tag.name, Tag);
Vue.component(Input.name, Input);
Vue.component(Select.name, Select);
Vue.component(Option.name, Option);
Vue.component(Switch.name, Switch);
Vue.component(DatePicker.name, DatePicker);
Vue.component(Dialog.name, Dialog);
Vue.component(Form.name, Form);
Vue.component(FormItem.name, FormItem);
Vue.component(Pagination.name, Pagination);

Vue.prototype.$http = http;
Vue.prototype.$confirm = MessageBox.confirm;
Vue.prototype.$message = Message;
Vue.config.productionTip = false

// 监听导航守卫
router.beforeEach((to, from, next) => {
  store.commit("getToken")
  const token = store.state.user.token
  if (!token && to.name !== "login") {
    next({ name: "login" })
  } else if (token && to.name ==="login") {
    next({name:"home"})
  } else{
    next()
  }
})

new Vue({
  store,
  router,
  render: h => h(App),
  created(){
    store.commit("addMenu",router)
  }
}).$mount('#app')
